//
//  ScanViewController.m
//  Kaiser
//
//  Created by wei wang on 2017/1/3.
//  Copyright © 2017年 wei wang. All rights reserved.
//

#import "ScanViewController.h"
#import "ScanfQRCodeView.h"
#import "AddDoorSystemInfoViewController.h"
@interface ScanViewController ()<ScanfQRCodeViewDelegate,UIAlertViewDelegate>


@property (nonatomic, strong) ScanfQRCodeView *scanView;
@property (nonatomic, assign) int noticeCount;

@end

@implementation ScanViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

}

- (void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    self.noticeCount = 0;
    [self.scanView startScan];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setNavigationStyle];
    self.scanView = [[ScanfQRCodeView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.scanView.delegate = self;
    [self.view addSubview:self.scanView];
    [self.view sendSubviewToBack:self.scanView];
}


- (void)setNavigationStyle{
    
    [self setNavigationTitle:@"扫描添加" titleColor:[UIColor colorWithRed:210/255.0 green:177/255.0 blue:104/255.0 alpha:1]];
    [self setLeftButtonImage:[UIImage imageNamed:@"icon_back_nor"]];
    
}

- (void)scanfQRCode:(ScanfQRCodeView *)scanfview result:(NSString *)result{
    
    if(self.noticeCount ++ >3){
        
        [SVProgressHUD showInfoWithStatus:@"二维码不匹配,请联系客服"];
        self.noticeCount = 0;
        [self.scanView startScan];

        return;
    }
    
    AddDoorSystemInfoViewController *vc = [AddDoorSystemInfoViewController new];
    vc.indexView = self.indexView;
    vc.dsModel.uid = result;
    [self.navigationController pushViewController:vc animated:YES];
    
}


- (IBAction)addAction:(UIButton *)sender {
    
    
}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
    [SVProgressHUD dismiss];
    [self.scanView stopRunning];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/



@end
